package com.itany.cloud.controller;

import com.itany.cloud.entity.User;
import com.itany.cloud.service.UserSerivce;
import com.itany.cloud.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserSerivce userSerivce;

    @GetMapping
    public ResponseResult findAll(){
        return userSerivce.findAll();
    }

    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Integer id){
        return userSerivce.findById(id);
    }

    @PostMapping
    public ResponseResult addUser(User user){
        return userSerivce.addUser(user.getUsername(),user.getPassword(),user.getPhone(),user.getAddress());
    }

    @PutMapping
    public ResponseResult modifyUser(User user){
        return userSerivce.modifyUser(user.getId(),user.getUsername(),user.getPassword(),user.getPhone(),user.getAddress());
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable Integer id){
        return userSerivce.deleteUser(id);
    }
}
